<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="../../lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="../../css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
        .layui-form-item .layui-input-block {
            width: 400px;
        }
    </style>
</head>
<body>
<div class="layui-form layuimini-form">
    <div class="layui-form-item">
        <input type="hidden" name="id" id="uid" value="">
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="username" id="username" lay-verify="required" lay-reqtext="用户名不能为空" placeholder="请输入用户名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">密码</label>
        <div class="layui-input-block">
            <input type="text" name="password" id="password" lay-verify="required" lay-reqtext="密码不能为空" placeholder="请输入密码" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">姓名</label>
        <div class="layui-input-block">
            <input type="text" name="name" id="name" lay-verify="required" lay-reqtext="姓名不能为空" placeholder="请输入姓名" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">性别</label>
        <div class="layui-input-block">
            <input type="radio" name="sex" id="sex1" value="1" title="男">
            <input type="radio" name="sex" id="sex0" value="0" title="女">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">年龄</label>
        <div class="layui-input-block">
            <input type="text" name="age" id="age" lay-verify="required" lay-reqtext="年龄不能为空" placeholder="请输入年龄" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">手机</label>
        <div class="layui-input-block">
            <input type="number" name="phone" id="phone" lay-verify="required" lay-reqtext="手机不能为空" placeholder="请输入手机" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">邮箱</label>
        <div class="layui-input-block">
            <input type="email" name="email" id="email" placeholder="请输入邮箱" value="" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">会员</label>
        <div class="layui-input-block">
            <input type="radio" name="identity" id="identity1" value="1" title="会员">
            <input type="radio" name="identity" id="identity0" value="0" title="非会员">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label required">身份</label>
        <div class="layui-input-block">
            <input type="radio" name="power" id="power1" value="1" title="管理员">
            <input type="radio" name="power" id="power0" value="0" title="普通用户">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">确认保存</button>
        </div>
    </div>
</div>
</div>
<script src="../../lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script src="../../lib/jquery-3.4.1/jquery-3.4.1.min.js"></script>
<script>
    layui.use(['form'], function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.$;

        //监听提交
        form.on('submit(saveBtn)', function (data) {
            var index = layer.confirm('确认是否修改？', {
                title: '修改',
                icon:'3'
            }, function (index) {
                let send_data = JSON.stringify(data.field);
                $.ajax({
                    url: '${path}/user/admin/editUser',
                    type: "post",
                    data: send_data,
                    contentType: 'application/json;charset=utf-8',
                    dataType:'json',
                    success: function(result){
                        if(result.code=="200"){
                            layer.msg('修改成功！', {icon:1, time: 2000},function (){
                                parent.location.reload();
                                // 关闭弹出层
                                layer.close(index);
                                let iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                            });
                        }else {
                            layer.msg('修改失败！', {icon:2});
                        }
                    }
                });

            });

            return false;
        });
    });

    function child(data){
        layui.use(['form'], function () {
            var form = layui.form,
                $ = layui.$;
            console.log(data)
            // //获取子页面的元素，进行数据渲染
            $("#username").val(data.username);
            $('#name').val(data.name);
            $('#phone').val(data.phone);
            $('#email').val(data.email);
            $('#password').val(data.password);
            $('#password').val(data.password);
            $('#uid').val(data.id);
            $('#age').val(data.age);
            $('#sex'+data.sex).prop("checked",true);
            $('#identity'+data.identity).prop("checked",true);
            $('#power'+data.power).prop("checked",true);
            form.render();          //表单渲染
        });

    }
</script>
</body>
</html>